package com.cloud.cloudvideo.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.cloudvideo.entity.ResultModel;
import com.cloud.cloudvideo.entity.TreePojo;
import com.cloud.cloudvideo.entity.VideoCate;
import com.cloud.cloudvideo.service.VideoCateService;

@Controller
@RequestMapping("/videocate")
public class VideoCateController {

	@Autowired
	private VideoCateService cateService;

	@GetMapping("/tolist")
	public String tolist() {
		return "manager/videocate/list";
	}

	@GetMapping("/list")
	@ResponseBody
	public ResultModel<List<VideoCate>> list() {
		List<VideoCate> list = cateService.list();
		return ResultModel.successWithData(list, list.size());
	}

	@GetMapping("/toAdd")
	public String toAdd() {
		return "manager/videocate/add";
	}

	@PostMapping("/add")
	@ResponseBody
	public ResultModel add(VideoCate cate) {
		cateService.modify(cate);
		return ResultModel.successWithNoData();
	}
	
	@GetMapping("/totreelist")
	public String totreelist() {
		return "manager/videocate/treelist";
	}
	

	
	@GetMapping("/treelist")
	@ResponseBody
	public ResultModel<List<TreePojo>> treelist() {
		List<TreePojo> list =   cateService.treelist();
		return ResultModel.successWithData(list,list.size());
	}
	
	
	@PostMapping("/del")
	public ResultModel del(Long id) {
		cateService.del(id);
		return ResultModel.successWithNoData();
	}
	

	@GetMapping("/toModify")
	public String toModify(Long id,Model model) {
		Map<String,Object> map = cateService.cateInfo(id);
		model.addAttribute("cate", map.get("cate"));
		model.addAttribute("pcate", map.get("pcate"));
		return "manager/videocate/add";
	}
	
}
